import java.util.Arrays;

/**
 * Created with Intellij IDEA
 * Description
 * User:ASUS
 * Date:2024-09-11
 * Time:20:39
 */
public class Stack {
    int[] element;
    int usedSize;
    public Stack(){
        this.element=new int[10];
    }
    public int push(int val){
        if(isFull()){
            this.element= Arrays.copyOf(element,2*element.length);
        }
        element[usedSize++]=val;
        return val;
    }
    public int pop(){
        int val=peek();
        usedSize--;
        return val;
    }
    public int peek(){
        if(empty()){
            throw new RuntimeException("栈为空，无法获取栈顶元素");
        }
        return element[usedSize-1];
    }
    public boolean empty(){
        return 0==usedSize;
    }
    public boolean isFull(){
        return usedSize==element.length;
    }
}
